package ${setApiPackageName};

import com.fangx.app.basic.domain.BaseResult;
import com.fangx.app.basic.CommonHandelApi;
import ${setDomainPackageName}.${DOMAIN_CLASSNAME};
import ${setServicePackageName}.${SERVICE_CLASSNAME};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import ${pagingQueryDto};
import ${pagingResultDto};

/**
 * Description:${tableAnnotation}管理后台接口类
 * @author ${author}
 * @date ${date}
 */
@Api(description = "${tableAnnotation}管理后台接口")
@RestController
@RequestMapping("/manage/${tableRequestPath}")
public class ${API_CLASSNAME} extends CommonHandelApi {

    private final ${SERVICE_CLASSNAME} ${service_classname};

    @Autowired
    public ${API_CLASSNAME}(${SERVICE_CLASSNAME} ${service_classname}) {
        this.${service_classname} = ${service_classname};
    }

    @PostMapping("/create")
    @ApiOperation(value = "添加${tableAnnotation}")
    <#--@ApiImplicitParam(paramType = "body", name = "${domain_classname}", value = "要添加的${tableAnnotation}", required = true, dataType = "${tableName}")-->
    public ResponseEntity<BaseResult<Integer>> create(@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}) {
        <#--log.debug("添加${tableAnnotation}\t param:{}",${domain_classname});-->

        return result(${service_classname}.create(${domain_classname}));
    }

    @PutMapping("/update/{id}")
    @ApiOperation(value = "根据id更新${tableAnnotation}")
    @ApiImplicitParams({
        @ApiImplicitParam(paramType = "path", name = "id", value = "id", required = true, dataType = "int"),
    })
    public ResponseEntity<BaseResult<Integer>> update(@PathVariable("id") ${primaryKeyModtype} id,@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}) {
        <#--log.debug("根据id更新${tableAnnotation}\t id:{} param:{}",id,${domain_classname});-->
        ${domain_classname}.set${primaryKeyJava}(id);

        return result(${service_classname}.updateById(${domain_classname}));
    }

    @DeleteMapping("/{ids}")
    @ApiOperation(value = "根据ids删除${tableAnnotation}")
    @ApiImplicitParam(paramType = "path", name = "ids", value = "要删除${tableAnnotation}的ids,逗号分割", required = true, dataType = "String")
    public ResponseEntity<BaseResult<Integer>> deleteByIds(@PathVariable("ids") String ids) {
        <#--log.debug("根据ids删除${tableAnnotation}\t param:{}",ids);-->

        return result(${service_classname}.deleteByIds(ids));
    }

    @ApiOperation(value = "根据id查询${tableAnnotation}")
    @GetMapping("/{id}")
    public ResponseEntity<BaseResult<${DOMAIN_CLASSNAME}>> find${DOMAIN_CLASSNAME}(@PathVariable("id") ${primaryKeyModtype} id) {
        <#--log.debug("根据id查找${tableAnnotation}\t param:{}",id);-->

        return result(${service_classname}.selectById(id));
    }

    @PostMapping("/pages")
    @ApiOperation(value = "查询${tableAnnotation}分页列表")
    public ResponseEntity<BaseResult<PagingResultDto<${DOMAIN_CLASSNAME}>>> pageQuery(@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}){
        <#--log.debug("查询${tableAnnotation}分页列表\t param:{}",${domain_classname});-->

        return result(${service_classname}.pageList(PagingQueryDto.startPaging(${domain_classname})));
    }

    <#--@PostMapping("/lists")-->
    <#--@ApiOperation(value = "查询${tableAnnotation}列表")-->
    <#--public ResponseEntity<List<${DOMAIN_CLASSNAME}>> listQuery(@RequestBody ${DOMAIN_CLASSNAME} ${domain_classname}){-->
        <#--log.debug("查询${tableAnnotation}列表\t param:{}",${domain_classname});-->

        <#--return ResponseEntity-->
            <#--.ok(-->
                <#--${service_classname}-->
                    <#--.pageList(PagingQueryDto.start(${domain_classname})-->
                    <#--).getRows()-->
            <#--);-->
    <#--}-->

}
